import jsonpath
import requests

from litemall.utils.log_util import logger


class BaseApi:

        __REQ = {
            "method": "POST",
            "url": "https://litemall.hogwarts.ceshiren.com/admin/auth/login",
            "json": {"username": "hogwarts", "password": "test12345", "code": ""}
        }

        def send_api(self, req):
            logger.info(f"请求数据为 {req}")
            r = requests.request(**req)
            logger.info(f"响应体为 {r.text}")
            return r

        def get_token(self):
            r = self.send_api(self.__REQ)
            token = jsonpath.jsonpath(r.json(), "$..token")[0]
            return token


